package com.ynny.chapter04.dao;

import com.ynny.chapter04.base.BaseDAO;
import com.ynny.chapter04.entity.User;

import java.util.List;

public class UserDaoImpl extends BaseDAO<User> implements UserDao {
    @Override
    public User selectUserByUserNameAndPassword(String userName, String password) {
        String sql = "select * from user where userName=? and password=?";
        User user = selectOne(sql, userName, password);
        return user;
    }

    @Override
    public User selectUserByUserName(String userName) {

        String sql = "select * from user where userName=?";
        User user = selectOne(sql, userName);
        return user;
    }

    @Override
    public int insertUser(User user) {

        String sql = "insert into user(userName,password) values(?,?)";
        int i = insert(sql, user.getUserName(), user.getPassword());
        return i;
    }

    @Override
    public List<User> selectAllUsers() {

        String sql = "select * from user";
        List<User> users = selectAll(sql);
        return users;
    }
}
